package com.onefinger.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.onefinger.aspect.Cache;
import com.onefinger.aspect.Uncache;
import com.onefinger.domain.Device;
import com.onefinger.repository.GenericRepository;

public class DeviceService implements IDeviceService {

	@Autowired
	GenericRepository<Device> genericRepository; 
	
	@Cache(cacheKey="devices", expireTime=0)
	public List<Device> list() {
		return genericRepository.getList(Device.class);
	}

	
	@Uncache(cacheKey="devices")
	public boolean save(Device device) {
		try {
			genericRepository.save(device);
		} catch (Exception e) {
			
			return false;
		}
		return true;
	}

	@Uncache(cacheKey="devices")
	public boolean remove(Device device) {
		try {
			genericRepository.remove(device);
		} catch (Exception e) {
			
			return false;
		}
		return true;
	}

}
